package 创建的方式;

public class Join {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    //循环3次，每次休眠1秒并打印
                    for(int i=0; i<3; i++){
                        System.out.println("t run: "+i);
                        Thread.sleep(1000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        //t线程加入到当前线程（main）：当前线程等待t线程执行完，再接着执行
        t.join();
        System.out.println("main run");
    }
}

